﻿///<reference path="BasketItemModel.ts"/>
///<reference path="PromotionModel.ts"/>
///<reference path="../../Scripts/typings/linq/linq.3.0.3-Beta4.d.ts"/>


module Enferno.Public.Web.Components.Models {

    export class BasketModel {
        public id: string;
        public items: Array<BasketItemModel>;
        public freights: Array<BasketItemModel>;
        public payments: Array<BasketItemModel>;
        public promotions: Array<PromotionModel>;
        public customerId: number;
        public companyId: number;
        public onHandMessage: string;
        public comment: string;
        public orderReference: string;

        constructor();
        constructor(serverObject: any);
        constructor(serverObject?: any) {
            if (serverObject != null) {
                this.createFromServerObject(serverObject);
            }
        }

        private createFromServerObject(serverObject: any) {
            this.id = serverObject.id;
            this.items = serverObject.items != null ? Enumerable.from(serverObject.items).select(item => new BasketItemModel(item)).toArray() : [];
            this.freights = serverObject.freights != null ? Enumerable.from(serverObject.freights).select(freight => new BasketItemModel(freight)).toArray() : [];
            this.payments = serverObject.payments != null ? Enumerable.from(serverObject.payments).select(payment => new BasketItemModel(payment)).toArray() : [];
            this.promotions = serverObject.promotions != null ? Enumerable.from(serverObject.promotions).select(promotion => new PromotionModel(promotion)).toArray() : [];
            this.customerId = serverObject.customerId;
            this.companyId = serverObject.companyId;
            this.onHandMessage = serverObject.onHandMessage;
            this.comment = serverObject.comment;
            this.orderReference = serverObject.orderReference;
        }
    }
}